package com.pinc.exam;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CheckedListItem extends RelativeLayout implements Checkable {
	private LayoutInflater mInflater;
	private RelativeLayout mTop;
	private boolean mBoolean;
	private ImageView iv_mark;
	private TextView tv_1;
	private TextView tv_2;

	public CheckedListItem(Context context) {
		this(context, null);
	}

	public CheckedListItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		mInflater = LayoutInflater.from(context);
		mTop = (RelativeLayout) mInflater.inflate(R.layout.checked_list_item, this);
		iv_mark = (ImageView) mTop.findViewById(R.id.imageView_check);
		tv_1 = (TextView) mTop.findViewById(R.id.textView1);
		tv_2 = (TextView) mTop.findViewById(R.id.textView2);
	}

	@Override
	public boolean isChecked() {
		return mBoolean;
	}

	@Override
	public void setChecked(boolean checked) {
		mBoolean = checked;
		updateMark();
	}

	@Override
	public void toggle() {
		mBoolean = !mBoolean;
		updateMark();
	}

	public void setText1(String str)
	{
		tv_1.setText(str);
	}

	public void setText2(String str)
	{
		tv_2.setText(str);
	}

	private void updateMark()
	{
		if ( mBoolean)
			iv_mark.setVisibility(View.VISIBLE);
		else
			iv_mark.setVisibility(View.INVISIBLE);
	}
}
